package com.lianrui.app.platform.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.lianrui.commons.exception.BusinessException;
import com.lianrui.commons.exception.SystemException;
import com.lianrui.message.ISystemMessage;

/**
 * 功能描述：平台控制器
 *
 * @author LJQ
 *
 * 2015年12月28日 下午3:03:10
 */
@Controller
@RequestMapping("/")
public class PlatformController {
	
	private static final Logger LOGGER = LoggerFactory.getLogger(PlatformController.class);
	
	@RequestMapping
	public String initialize() {
		return "index";
	}
	
	@RequestMapping(value = "/main", method = RequestMethod.GET)
	public String main(HttpServletRequest request, HttpServletResponse response) {
		return "main";
	}
	
	@RequestMapping(value = "/login", method = RequestMethod.GET)
	public String login(HttpServletRequest request) {
		return "login";
	}
	
	@RequestMapping(value = "/monitor", method = RequestMethod.GET)
	public String monitor() {
		return "monitor";
	}
	
	@RequestMapping(value = "/logout", method = RequestMethod.GET)
	public String logout(HttpServletRequest request) {
		HttpSession session = request.getSession();
		session.invalidate();
		return "login";
	}
	
	@RequestMapping(value = "/setLocal", method = RequestMethod.GET)
	public String setLocal(HttpServletRequest request) {
		return "redirect:/main";
	}
	
	@ExceptionHandler
	public String error(Throwable e, Model model) {
		model.addAttribute("errorMessage", e.getMessage());
		return "/error/error-sys";
	}
    
    @RequestMapping("test")
    public void test() throws BusinessException {
        throw new SystemException(ISystemMessage.SYS_CONTROLLER_FAILED, LOGGER, "controller", "test");   
    }
}
